﻿<!--#include FILE="Admin_Include.asp"-->
<%
Response.Write "<!DOCTYPE html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<title>Web Edit</title>" & vbCrlf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
Response.Write "<link rel='stylesheet' type='text/css' href='../Js/Codemirror/Codemirror.css'/>" & vbCrLf
Response.Write "<link rel='stylesheet' type='text/css' href='../Plugins/editor/css/editormd.min.css'/>" & vbCrLf
Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
Response.Write "<link href='../Style/global.css' rel='stylesheet' type='text/css' />" & vbCrLf
Response.Write "<link href='../Style/font.css' rel='stylesheet' type='text/css' />" & vbCrLf
Response.Write "<script type='text/javascript'>" & vbCrLf
Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
Response.Write "</script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/Codemirror.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/xml.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/css.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/javascript.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/htmlmixed.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script src='../Js/Codemirror/mirrorframe.js' type='text/javascript'></script>" & vbCrLf
Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
Response.Write "<script type=""text/javascript"" src=""../Plugins/editor/editormd.min.js""></script>" & vbCrLf
Response.Write "</head>" & vbCrlf
Response.Write "<body>" & vbCrlf

dim gContent,gStr
Select Case gAct
Case "read"
	Readit
Case "write"
	Writeit
End Select

Sub ReadIt
	dim i1,i2
	if gPath="" Then exit sub
	gStr=procCheckFile(gPath,1)
	if gStr<>"ok" Then htmEnd gStr,1,""
	gcontent=LoadFile(gPath)
End Sub

Sub WriteIt
	Dim stm
	if Request.form("filepath")="" Then  HtmEnd "请输入路径!",1,""
	gStr=procCheckFile(gPath,2)
	if gStr<>"ok" Then htmEnd gStr,1,""
	gContent=Request.form("content")
	On Error Resume Next
	Err.Clear
	Set stm = Server.CreateObject("Adodb.Stream")
		stm.Type = 2
		stm.mode = 3
		stm.charset = "utf-8"
		stm.Open
		stm.WriteText gContent
		stm.SaveToFile Server.Mappath(gPath), 2
		stm.flush
		stm.Close
	Set stm = Nothing
	If Err.Number<>0 Then
		Err.Clear
		HtmEnd "写入文件错误！可能的原因是：<br>1. " & gPath & " 文件没有写权限。<br>2. 服务器已禁用 Adodb.Stream 对象。",1,""
	End If	
End Sub

function setcode(gstr)
	dim str1,str2,i1,i2
	i1=1
	i2=2
	gstr=Server.HtmlEncode(gstr)
	gstr=Replace(gstr,"  "," &nbsp;")
	do while i1>0 and i2>i1
		i1=instr(i1,gstr,"![")
		if i1<1 Then
			exit do
		end if
		i2=instr(i1+2,gstr,"!]")
		if i2<i1 Then
			exit do
		end if
		str1=mid(gstr,i1,i2-i1+2)
		str2=mid(gstr,i1+2,i2-i1-2)
		str2=replace(str2,"&gt;",">")
		str2=replace(str2,"&lt;","<")
		str2=replace(str2,"&quot;","""")
		str2=replace(str2,"&nbsp;"," ")
		str2=replace(str2,"&amp;","&")
		str2=Replace(str2,vbcrlf,"<!---->")
		gstr=replace(gstr,str1,str2)
	loop
	gstr=replace(gstr,vbCrLf,"<BR>"&vbCrLf)
	gstr=replace(gstr,"<!---->",vbcrlf)
	setcode=gstr
end function

Response.Write "<script language=""JavaScript"">" & vbCrlf
Response.Write "var lg_strback;" & vbCrlf
Response.Write "lg_strback='';" & vbCrlf
Response.Write "function readit()" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "if(!document.form2.filepath.value)" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "IsAlertFocus('请输入文件路径!','filepath');" & vbCrlf
Response.Write "return;" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "document.form2.action='" & gFileName & "?act=read&path='+document.form2.filepath.value;" & vbCrlf
Response.Write "document.form2.submit();" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "function writeit()" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "if(!document.form2.filepath.value)" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "IsAlertFocus('请输入文件路径!','filepath');" & vbCrlf
Response.Write "return;" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "document.getElementById('content').value=content.getValue();" & vbCrlf
Response.Write "document.form2.action='" & gFileName & "?act=write&path='+document.form2.filepath.value;" & vbCrlf
Response.Write "document.form2.submit();" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "function proc_back()" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "document.form2.action=geturl(document.form2);" & vbCrlf
Response.Write "document.form2.act.value='none';" & vbCrlf
Response.Write "document.form2.submit();" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "function proc_editok()" & vbCrlf
Response.Write "{" & vbCrlf
Response.Write "document.form2.action=geturl(document.form2);" & vbCrlf
Response.Write "document.form2.submit();" & vbCrlf
Response.Write "}" & vbCrlf
Response.Write "</script>" & vbCrlf
Response.Write "<form name=""form2"" method=""post"" action=""" & Request.Servervariables("SCRIPT_NAME") & """ onSubmit=""return checkit();"">" & vbCrlf
Response.Write "<div class=""admin-main layui-anim layui-anim-upbit"">" & vbCrLf
Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
Response.Write "<tr class=""title"">" & vbCrlf
Response.Write "<td height=""25"" align=""center"">文件位置: <input type=""text"" id=""filepath"" name=""filepath"" style=""width:500px; height:21px;"" maxlength=""50"" size=""1"" value=""" & gPath & """>&nbsp;<button type=""button"" class=""layui-btn"" hidefocus=""true"" onClick=""readit();"">读文件</button></td>" & vbCrlf
Response.Write "</tr>" & vbCrlf
Response.Write "<tr>" & vbCrlf
Response.Write "<td><div id=""editormd""></div><textarea id=""content"" name=""content"" style=""display:none;"">" & Server.HtmlEncode(gcontent) & "</textarea></td>" & vbCrlf
Response.Write "<script type='text/javascript'>" & vbCrLf
Response.Write "content = editormd(""editormd"", {" & vbCrLf
Response.Write "	width : ""100%""," & vbCrLf
Response.Write "	height : ""300px""," & vbCrLf
Response.Write "	watch : false," & vbCrLf
Response.Write "	toolbar : false," & vbCrLf
Response.Write "	codeFold : true," & vbCrLf
Response.Write "	searchReplace : true," & vbCrLf
Response.Write "	placeholder : ""请输入代码""," & vbCrLf
Response.Write "	value : document.getElementById(""content"").value," & vbCrLf
Response.Write "	theme : ""default""," & vbCrLf
Response.Write "	mode : ""htmlmixed""," & vbCrLf
Response.Write "	path : '../Plugins/editor/lib/'" & vbCrLf
Response.Write "});" & vbCrLf
Response.Write "</script>" & vbCrLf
Response.Write "</tr>" & vbCrlf
Response.Write "<tr>" & vbCrlf
Response.Write "<td align=""center""><button type=""button"" class=""layui-btn"" hidefocus=""true"" accesskey=""s"" onClick=""writeit();"">保存文件[S]</button>&nbsp;<button type=""button"" class=""layui-btn"" hidefocus=""true"" accesskey=""c"" onClick=""ownerDialog.close();"">关闭[C]</button></td>" & vbCrlf
Response.Write "</tr>" & vbCrlf
Response.Write "</table>" & vbCrlf
Response.Write "</div>" & vbCrLf
Response.Write "</form>" & vbCrlf
Response.Write "</body>" & vbCrlf
Response.Write "</html>"
%>